package main

import (
	"fmt"
	"reflect"
)

var a int
var b int = 100
var (
	c string
	d int
	e string = "10sdcsd"
)

func main() {
	//变量申明测试
	bianliangshenm()
	//类型转换
	changeType()
	//常量申明测试
	constShenming()

}

const name = "nishi "
const name2 string = "nishi "
const (
	cat = "cat"
	dog = "dog"
)
const apple, banana = "1wew", 3
const alen = len(apple)

func constShenming() {
	fmt.Println(name)
	fmt.Println(name2)
	fmt.Println(cat)
	fmt.Println(dog)
	fmt.Println(apple)
	fmt.Println(banana)
	fmt.Println()
}

/**
变量申明测试
*/
func bianliangshenm() {
	fmt.Print(a)
	fmt.Println()
	fmt.Print(b)
	fmt.Println()
	fmt.Print(c)
	fmt.Println()
	fmt.Print(d)
	fmt.Println()
	fmt.Print(e)
	fmt.Println()
	var (
		c string
		d int
		e string = "fff"
	)
	fmt.Print(c)
	fmt.Println()
	fmt.Print(d)
	fmt.Println()
	fmt.Print(e)
	fmt.Println()
	var q, w, r int = 1, 2, 3
	fmt.Println(q, w, r)
	var qq, ww, rr = 1, 2, 3
	fmt.Println(qq, ww, rr)
	qqq, www, rrr := 1, 2, 3
	//此种申明方式只能用在函数体内
	fmt.Println(qqq, www, rrr)
	var q1, _, w1 = 1, 2, 3
	//下划线所占的位置会被抛弃
	//fmt.Println(q1,_,w1)会报错，下划线不能被打印出来
	fmt.Println(q1, w1)
}

/**
类型转换：会有精度上的损失 如浮点转int
*/
func changeType() {

	var a int = 3
	c := float32(a)
	fmt.Println(c)
	fmt.Println(reflect.TypeOf(c))

}
